home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / cluster_admin.idb / usr / cluster / bin / ClusterDiags.z / ClusterDiags
Text File  |  2002-10-15  |  7KB  |  273 lines

  1. #!/usr/sbin/perl
  2. #
  3. #  Copyright (C) 1998-2000, Silicon Graphics, Inc.
  4. #  All Rights Reserved.
  5. #
  6. #  UNPUBLISHED -- Rights reserved under the copyright laws of the United
  7. #  States.  Use of a copyright notice is precautionary only and does not
  8. #  imply publication or disclosure.
  9. #
  10. #  THIS SOFTWARE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF
  11. #  SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR
  12. #  DISCLOSURE IS STRICTLY PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN
  13. #  PERMISSION OF SILICON GRAPHICS, INC.
  14. #
  15. #  U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
  16. #  Use, duplication or disclosure by the Government is subject to
  17. #  restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph
  18. #  (c)(1)(ii) of the Rights in Technical Data and Computer Software
  19. #  clause at DFARS 252.227-7013 and/or in similar or successor clauses
  20. #  in the FAR, or the DOD or NASA FAR Supplement.  Unpublished-- rights
  21. #  reserved under the copyright laws of the United States.
  22. #  Contractor/manufacturer is Silicon Graphics, Inc.,
  23. #  2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  24. #
  25.  
  26. $LibDiagsPath = "/var/cluster/ha/diags";
  27. $DiagsPath = "/var/cluster/ha/diags";
  28.  
  29. require "$LibDiagsPath/libdiags.pl";
  30. require "$DiagsPath/ConnectivityTests";
  31. require "$DiagsPath/SerialTests";
  32. require "$DiagsPath/ResourceTypeTests.pl";
  33. require "$DiagsPath/ResourceGroupTests.pl";
  34. require "$DiagsPath/FailoverPolicyTests.pl";
  35. require "$DiagsPath/machine.pl";
  36.  
  37. sub Usage
  38. {
  39.   print "USAGE: ClusterDiags\n";
  40.   print "\t{ {{_RESOURCE=<name>} _RESOURCE_TYPE=<type>} or\n";
  41.   print "\t _RESOURCE_GROUP=<group> }\n";
  42.   print "\t _FAILOVER_POLICY=<policy> }\n";
  43.   print "\t{_CONNECTIVITY=<true|false> or \n" ;
  44.   print "\t _SERIAL=<true|false>}\n";
  45.   print "\t_CLUSTER=<cluster name>\n";
  46.   print "\t_DESTRUCTIVE=<true|false>, default false\n";
  47.   print "\t_NUM_MACHINES=<n, n >=1 > _MACHINE_<n>=<name, n >= 0> ... \n";
  48.   print "\t_VERBOSE=<true|false>, default false\n";
  49.   exit(1);
  50. }
  51.  
  52. sub ProcessArgs
  53. {
  54.   local ($argi, $newargi, $return_value);
  55.   local ($i, @machinelist);
  56.  
  57.   $return_value = $CD_SUCCESS;
  58.  
  59.   &LogEntry();
  60.  
  61.   if ($#ARGV < 0) {
  62.     &Usage();
  63.   }
  64.  
  65.   # Default commands.
  66.   $ResourceType = ALL;
  67.   $Resource = ALL;
  68.   $TestOption = ResourceType;
  69.  
  70.   $newargi = 0;
  71.   for ($argi = 0; $argi <= $#ARGV; $argi++) {
  72.       if ($ARGV[$argi] =~ /_RESOURCE_TYPE=(.*)/) {
  73.            $TestOption = ResourceType;
  74.     $ResourceType = $1;
  75.     $typeset = 1;
  76.  
  77.       }elsif ($ARGV[$argi] =~ /_RESOURCE_GROUP=(.*)/) {
  78.     $TestOption = ResourceGroup;
  79.     $ResourceGroup = $1;
  80.     $grpset = 1;
  81.  
  82.       }elsif ($ARGV[$argi] =~ /_FAILOVER_POLICY=(.*)/) {
  83.     $TestOption = FailoverPolicy;
  84.     $Policy = $1;
  85.     $polset = 1;
  86.  
  87.       }elsif ($ARGV[$argi] =~ /_RESOURCE=(.*)/) {
  88.     $TestOption = Resource;
  89.     $Resource = $1;
  90.     $resset = 1;
  91.  
  92.       }elsif ($ARGV[$argi] =~ /_CLUSTER=(.*)/) {
  93.     $Cluster = $1;
  94.     $cluset = 1;
  95.  
  96.       }elsif ($ARGV[$argi] =~ /_CONNECTIVITY=(.*)/) {
  97.     if ($1 eq "true") {
  98.       $conset = 1;
  99.       $TestOption = Connectivity;
  100.     }
  101.       }elsif ($ARGV[$argi] =~ /_SERIAL=(.*)/) {
  102.     if ($1 eq "true") {
  103.       $serset = 1;
  104.       $TestOption = Serial;
  105.     }
  106.       }elsif ($ARGV[$argi] =~ /_VERBOSE=(.*)/) {
  107.     $verbose = 1;
  108.       }elsif ($ARGV[$argi] =~ /_DESTRUCTIVE=(.*)/) {
  109.     if ($1 eq "true") {
  110.         &Warning("Executing the tests in destructive mode");
  111.         # Global variable, used in the resource scripts.
  112.         $DESTRUCTIVE=1;
  113.     } else {
  114.         $DESTRUCTIVE=0;
  115.     }
  116.       }elsif ($ARGV[$argi] =~ /_MACHINE_(\d+)=(.*)/) {
  117.     $MachineList = 1;
  118.     $List[$1] = $2;
  119.     $macset = 1;
  120.  
  121.       }elsif ($ARGV[$argi] =~ /_NUM_MACHINES=(.*)/) {
  122.     $num_machines = $1 - 1;
  123.     $MachineList = 1;
  124.     $macset = 1;
  125.  
  126.       } else {
  127.     Usage();
  128.       } # end if ( ...
  129.     } # end for ( ...
  130.  
  131.   # Check that we have the all arguments needed to fulfill the requrest
  132.   if ($conset && $serset) {
  133.       &Warning("you cannot choose both _CONNECTIVITY and _SERIAL");
  134.       &Usage();
  135.   }
  136.   if ($conset && $resset) {
  137.     &Warning("you cannot choose both _CONNECTIVITY and _RESOURCE");
  138.     &Usage();
  139.   }
  140.   if ($conset && $grpset) {
  141.     &Warning("you cannot choose both _CONNECTIVITY and _RESOURCE_GROUP");
  142.     &Usage();
  143.   }
  144.   if ($conset && $polset) {
  145.     &Warning("you cannot choose both _CONNECTIVITY and _FAILOVER_POLICY");
  146.     &Usage();
  147.   }
  148.   if ($conset && $typeset) {
  149.     &Warning("you cannot choose both _CONNECTIVITY and _RESOURCE_TYPE");
  150.     &Usage();
  151.   }
  152.   if (($resset) && (!$typeset)) {
  153.     &Warning("you must set both _RESOURCE and _RESOURCE_TYPE");
  154.     &Usage();
  155.   }
  156.   if (!$cluset) {
  157.     &Warning("you must supply the _CLUSTER parameter");
  158.     &Usage();
  159.   }
  160.   if (($typeset) && ($grpset)) {
  161.     &Warning("you cannot choose both _RESOURCE_TYPE and _RESOURCE_GROUP");
  162.     &Usage();
  163.   }
  164.   if ($typeset && $polset) {
  165.     &Warning("you cannot choose both _RESOURCE_TYPE and _FAILOVER_POLICY");
  166.     &Usage();
  167.   }
  168.   if ($grpset && $polset) {
  169.     &Warning("you cannot choose both _RESOURCE_GROUP and _FAILOVER_POLICY");
  170.     &Usage();
  171.   }
  172.   if (!$macset) {
  173.     $Local = 1;
  174.   } else {
  175.       if (scalar(@List) != $num_machines+1) {
  176.       &Warning("internal error: number of machines don't match, list = %d, number = %d",
  177.            scalar(@List),$num_machines+1);
  178.       &Usage();
  179.       }
  180.   }
  181.   return($return_value);
  182. }
  183.  
  184. sub PerformTest {
  185.   local (@machines) = @_;
  186.   local ($machine);
  187.   local ($retv);
  188.  
  189.   &LogEntry();
  190.   if ($TestOption eq Connectivity) {
  191.     $retv=&PerformConnectivityTests(@machines);
  192.     &ExitStatus($retv);
  193.   } elsif ($TestOption eq Serial) {
  194.     $retv=&PerformSerialTests(@machines);
  195.     &ExitStatus($retv);
  196.   } else {
  197.     foreach $machine (@machines) {
  198.       &Verbose("running %s test on node %s",
  199.            $TestOption,$machine);
  200.  
  201.       # Always test the machine specification
  202.       if (!($retv=&PerformMachineTests($machine))) {
  203.     &ExitStatus($retv);
  204.     return ($retv);
  205.       }
  206.  
  207.       if ($TestOption eq ResourceType) {
  208.     # The same tests handle both resources and resource types.
  209.     $retv=&PerformResourceTypesTests($machine);
  210.       } elsif ($TestOption eq ResourceGroup) {
  211.     $retv=&PerformResourceGroupTests($machine);
  212.       } elsif ($TestOption eq Resource) {
  213.     # The same tests handle both resources and resource types.
  214.     $retv=&PerformResourceTypesTests($machine,$Resource);
  215.       } elsif ($TestOption eq FailoverPolicy) {
  216.     $retv=&PerformFailoverPolicyTests($machine,$Resource);
  217.       }  else {
  218.     &Warning("unknown action %s requested",$TestOption);
  219.     $retv=$CD_FAILURE;
  220.       }
  221.     }
  222.   }
  223.   return $retv;
  224. }
  225.  
  226. # main:
  227. #
  228. #
  229.  
  230. # Before we do anything, set the global error counters etc
  231. $CD_ERRNO=$CD_SUCCESS;
  232. $CD_ERRCNT=0;
  233. $CD_TESTCNT=0;
  234.  
  235. if (&ProcessArgs()) {
  236.  
  237.   local ($retv)=$CD_SUCCESS;
  238.  
  239.   # Generate a hash table of node to machine names
  240.   NodetoHostname();
  241.  
  242.   if ($Local) {
  243.     if ($TestOption eq ResourceGroup) {
  244.     # run tests only for nodes in the AFD
  245.     @machinelist=GetMachinesinGroupAFD($ResourceGroup);
  246.     if (scalar(@machinelist) < 1) {
  247.         # error message already printed
  248.         &Debug("No machines found in AFD for resource group %s", $ResourceGroup);
  249.         $retv=$CD_FAILURE;
  250.     } else {
  251.         $retv=$CD_SUCCESS;
  252.     }
  253.     } else {
  254.     @machinelist=GetAllMachines();
  255.     }
  256.     if ($retv == $CD_SUCCESS) {
  257.     $retv=&PerformTest(@machinelist);
  258.     }
  259.   } else {
  260.     $retv=&PerformTest(@List);
  261.   }
  262.  
  263.   &PrintStatus();
  264.  
  265.   # Because the test use 1==success and 0==failure, which is opposite
  266.   # to normal scripting.
  267.   if ($CD_ERRNO == $CD_FAILURE) {
  268.     exit(1);
  269.   } else {
  270.     exit(0);
  271.   }
  272. }
  273.